import sys,os

from pyfaidx import Fasta


def format_seq(seq, wrap):
    seq = seq.upper()
    chunks = [seq[i:i+wrap] for i in range(0, len(seq), wrap)]
    return "\n".join(chunks) + "\n"

chrlist = ["Chr05", "Chr02", "Chr06", "Chr22", "Chr24", "Chr01", "Chr07", "Chr17", "Chr09", "Chr19", "Chr11", "Chr10", "Chr23", "Chr03"]
print(len(chrlist))
out = open(sys.argv[2], "w")

fasta = Fasta(sys.argv[1])

allchrlist = fasta.keys()
print(allchrlist)

for i in allchrlist:
    tmp = i[4:]
    print(tmp)
    if tmp in chrlist:
        print("reverse")
        seq = str(fasta[i][0:].reverse.complement.seq)
    else:
        seq = str(fasta[i][0:].seq)
    seq = format_seq(seq, 60)
    out.write(">" + i + "\n" + seq)

out.close()

